﻿@model RBS.Core.Model.D_Order
@{
    ViewBag.Title = "订单";
    Layout = ""; 
}
<meta name="description" content="呷饭网" />
    <meta name="keywords" content="呷饭网" />
    <meta name="copyright" content="www.sweetwill.com" />
    <script src="http://tjs.sjs.sinajs.cn/open/api/js/wb.js" type="text/javascript" charset="utf-8"></script>
    @*    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />*@
    <link href="@Url.Content("~/Content/skin1/homepage.css")" rel="stylesheet" /> 
    <link href="@Url.Content("~/Content/style.css")" rel="stylesheet" type="text/css" />
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script src="~/Scripts/Validform_v5.3.2_min.js"></script>
    <script type="text/javascript" src="~/scripts/lhgdialog/lhgdialog.js?skin=idialog"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script> 
    <script src="~/Scripts/mustache.js"></script>
<link href="~/Scripts/datepicker/skin/WdatePicker.css" rel="stylesheet" />
<script src="~/Scripts/datepicker/lang/zh-cn.js"></script>
<script src="~/Scripts/datepicker/WdatePicker.js"></script>

@using (Ajax.BeginForm("Order", "Store", new AjaxOptions { OnSuccess = "OnSuccess" }, new { id = "OrderForm" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.H_Id) 
    @Html.HiddenFor(model => model.Id)  
    <div id="content"> 
        <div id="mainContent1">
            <div class="tab-content destineorder">
                <dl>
                    <dt><b>*</b>预订吃饭日期</dt>
                    <dd>
                        @Html.TextBoxFor(model => model.ReserveDate, null, new { @class = "input small w120", onfocus = "WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-{%d}'})" })
                         @{ 
                              var times= new SelectList(new List<SelectListItem>
                                            {
                                                    new SelectListItem {Text = "11:00", Value = "11:00"},
                                                    new SelectListItem {Text = "11:30", Value = "11:30"},
                                                    new SelectListItem {Text = "12:00", Value = "12:00"},
                                                    new SelectListItem {Text = "12:30", Value = "12:30"},
                                                    new SelectListItem {Text = "13:00", Value = "13:00"},
                                                    new SelectListItem {Text = "13:30", Value = "13:30"},
                                                    new SelectListItem {Text = "14:00", Value = "14:00"},
                                                    new SelectListItem {Text = "14:30", Value = "14:30"},
                                                    new SelectListItem {Text = "15:00", Value = "15:00"},
                                                    new SelectListItem {Text = "15:30", Value = "15:30"},
                                                    new SelectListItem {Text = "16:00", Value = "16:00"},
                                                    new SelectListItem {Text = "16:30", Value = "16:30"},
                                                    new SelectListItem {Text = "17:00", Value = "17:00"},
                                                    new SelectListItem {Text = "17:30", Value = "17:30"},
                                                    new SelectListItem {Text = "18:00", Value = "18:00"},
                                                    new SelectListItem {Text = "18:30", Value = "18:30"},
                                                    new SelectListItem {Text = "19:00", Value = "19:00"},
                                                    new SelectListItem {Text = "19:30", Value = "19:30"}
                                            }, "Value", "Text", Model.ReserveTime); 
                        } 
                        @Html.DropDownListFor(model => model.ReserveTime,times,new{datatype="time",errormsg="吃饭时间不能小于当前时间",nullmsg="请选择时间"}) 
                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>就餐人数</dt>
                    <dd>
                        @Html.TextBoxFor(model => model.DineNum, null, new { @class = "input normal w100", datatype = "n", value = "" })
                        <span class="Validform_checktip">*就餐人数</span>
                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>餐位情况</dt>
                    <dd class="ltable">
                        <label for="Dinecondition">大厅</label>
                        @Html.RadioButton("Dinecondition", "大厅")
                        <label for="Dinecondition">包间</label>
                        @Html.RadioButton("Dinecondition", "包间")
                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>桌位</dt>
                    <dd>
                        @Html.HiddenFor(model => model.DineTable)
                         @Html.Hidden("OldDineTable",null,new{value=@ViewBag.DineTable})
                        <script type="text/template" id="SeatTemplate">
                            <li id="li{{Id}}" name="{{Name}}">
                                <p>
                                    <a href="{{Picture}}" target="_blank">
                                        <img src="@(RBS.Common.ConfigHelper.GetConfigString("hotelWeb")){{Picture}}" /></a>
                                </p>
                                <h4>
                                    <input type="radio" id="seat{{Id}}" name="seat" value="{{Id}}" onclick="selectTable('{{Id}}', '{{Name}}')"  {{s}} />{{Name}}</h4>
                            </li>
                        </script>

                        <ul id="seatUl"></ul>
                        <span id="selectTable" class="Validform_checktip"></span>
                    </dd>
                </dl>

                <dl>
                    <dt><b>*</b>联系人</dt>
                    <dd>

                        @Html.TextBoxFor(model => model.ContactUser, null, new { @class = "input normal w100" })
                        <span class="Validform_checktip">*联系人</span>

                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>用户手机</dt>
                    <dd>

                        @Html.TextBoxFor(model => model.ContactMobile, null, new { @class = "input normal w100" })
                        <span class="Validform_checktip">*用户手机</span>

                    </dd>
                </dl>
                <dl>
                    <dt>订单备注</dt>
                    <dd>

                        @Html.TextBoxFor(model => model.OrderRemark, null, new { @class = "input normal" })
                        <span class="Validform_checktip">*订单备注</span>

                    </dd>
                </dl>
                <div class="destineorderbtn">
                    @Html.Hidden("SetOrder")
                     @Html.Hidden("orderid")
                    <input type="submit" id="BtnNextOrder" value="提交"  class="btn" style="display: none" /> 
                </div>
            </div>
        </div>

        <div id="sideContent">
        </div>
    </div>
     
    <script>
        $.ajaxSetup({
            async: false
        });
        $(function () {
            if ($(".ltable :radio[id='Dinecondition']:checked").val() != "undefined") {
                GetSeat($(".ltable :radio[id='Dinecondition']:checked").val());
            }
            $(".ltable :radio[id='Dinecondition']").each(function () {
                $(this).click(function () {
                    GetSeat(this.value);
                });
            });
        });
        function selectTable(id, name) {
            $("#DineTable").val(id);
            $("#selectTable").html("您选择的是" + name);
        }
        function GetSeat(dineValue) {
            var url = "@Url.Action("GetSeat")?hid=" + @Model.H_Id +"&type=" + encodeURIComponent(dineValue);
            var dine = dineValue;
            $.ajax({
                url: url,
                type: 'Post',
                dataType: 'json',
                success: function (result) {
                    if (result == null)
                        return;
                    $("#seatUl").empty();
                    $.each(result.Data, function (index, row) {

                        var ss = "";
                        if (row.Id == $("#DineTable").val()) {
                            ss = "checked";
                        }
                        row.s = ss;
                        var template = $('#SeatTemplate').html(); //获取模版的html

                        var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                        $("#seatUl").append(bookData);
                    });
                }
            });
        }

        $("#OrderForm").Validform({
            datatype: {
                "time": function (gets, obj, curform, regxp) { 
                    return true;
                    /*参数gets是获取到的表单元素值，
                      obj为当前表单元素，
                      curform为当前验证的表单，
                      regxp为内置的一些正则表达式的引用。*/
                    /*
                                        var reg1 = regxp["m"],
                                            reg2 = /[\d]{7}/,
                                            mobile = curform.find(".mobile");
                    
                                        if (reg1.test(mobile.val())) { return true; }
                                        if (reg2.test(gets)) { return true; }
                    
                                        return false;*/
                }
            },
            ajaxPost: false
        });  
        function OnSuccess(s) {
           // alert(s); 
            document.getElementById('orderid').value = s;
        }
        var api = frameElement.api, W = api.opener; 
        api.button({
            id: 'valueOk',
            name: '确定',
            callback: ok
        }); 
        function ok() {
            $("#BtnNextOrder").submit();
            W.document.getElementById('orderid').value = document.getElementById('orderid').value; 
            W.document.getElementById('aAddOrder').text = "修改订单"; 
        };  
    </script>
 
        
} 